package thisgame;
import java.awt.*;

import java.awt.event.KeyEvent;

import java.awt.event.KeyListener;

public class SelectMain extends Frame {

	// int 대신 명확하게 enum을 정의해서 사용하겠음
	private enum Menu { EXIT, START;
		Menu() {
		}
	}

	class myKeyEvent implements KeyListener {
		public void keyPressed(KeyEvent e) {
		}

		public void keyReleased(KeyEvent e) {
			switch (e.getKeyCode()) {
			case KeyEvent.VK_UP:
				System.out.println("UP");
				whereCur = Menu.START;
				break;

			case KeyEvent.VK_RIGHT:
				System.out.println("RIGHT");
				break;

			case KeyEvent.VK_LEFT:
				System.out.println("LEFT");
				break;

			case KeyEvent.VK_DOWN:
				whereCur = Menu.EXIT;
				System.out.println("Down");
				break;

			case KeyEvent.VK_ENTER:
				System.out.println("Enter");

				if(whereCur == Menu.EXIT){
					dispose();
					System.exit(0);
				}else if(whereCur == Menu.START){
					dispose();
					new GamePlay();
				}
				break;
			}
			repaint();
		}

		public void keyTyped(KeyEvent e) {
		}
	}
	
	private Image sMainImage, curImage;
	private Menu whereCur = Menu.START;

	public SelectMain() {
		init();
		loading();
		start();
	}

	public void init() {
		// Frame Setting
		this.setBounds(0, 0, 800, 600);
		this.addWindowListener(new WinEvent());
		this.addKeyListener(new myKeyEvent());
		this.setVisible(true);
	}

	public void loading() {
		sMainImage = Toolkit.getDefaultToolkit().getImage("selectBG.JPG");
		curImage = Toolkit.getDefaultToolkit().getImage("cur.gif");
	}

	@Override
	public void paint(Graphics g) {
		g.drawImage(sMainImage, 0, 0, 800, 600, this);

		if (whereCur == Menu.START) {
			g.drawImage(curImage, 220, 360, this);
		}
		if (whereCur == Menu.EXIT) {
			g.drawImage(curImage, 220, 480, this);
		}
	}

	public void start() {
	}

	public void updata(Graphics g) {
		paint(g);
	}
	
	@Override
	public void update(Graphics g) {
		paint(g);
	}
}